package hapi.geom;

import hapi.math.Vector2D;

class Line {
	
	var a:Float;
	var b:Float;
	var c:Float;
	var coef:Float;
	
	public function new(a, b, c){
		this.a = a;
		this.b = b;
		this.c = c;
		coef = Math.sqrt(a*a + b*b);
	}
	
	public static function createFromPoints(p1:Vector2D, p2:Vector2D){
		var v = p2.minusNew(p1);
		var a = v.y;
		var b = -v.x;
		var c = -a*p1.x - b*p1.y;
		return new Line(a,b,c);
	}
	
	public inline function distance(p:Vector2D){
		return Math.abs(a*p.x + b*p.y + c)/coef;
	}
	
	public function clone() {
		return new Line(a,b,c);
	}
	
	public function equals(l){
		return  a == l.a && b == l.b && c == l.c;
	}
}